# Maintainer: Peter Budai <peterbudai at hotmail dot com>

_realname=gphoto2
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.5.28
pkgrel=1
pkgdesc="The gphoto2 commandline tool for accessing and controlling digital cameras (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='http://www.gphoto.org/'
msys2_repository_url="https://github.com/gphoto/gphoto2"
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libgphoto2"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-libltdl"
         "${MINGW_PACKAGE_PREFIX}-readline"
         "${MINGW_PACKAGE_PREFIX}-popt")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
validpgpkeys=('7C4AFD61D8AAE7570796A5172209D6902F969C95') # Marcus Meissner
source=("https://github.com/gphoto/gphoto2/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.xz"{,.asc}
        "01_gphoto_close_before_rename.patch")
sha256sums=('ff3e32c7bd2a129d817dcd9e75ce51834409b1966e1f20e74c427c32ae732afa'
            'SKIP'
            'ca4e431c4f2bca1272a6580ebab7d81a82fa38fad07624cc8c6328b458293b19')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/01_gphoto_close_before_rename.patch

  autoreconf -fiv
}

build() {
  [[ -d build-${MSYSTEM} ]] && rm -rf build-${MSYSTEM}
  cp -r ${_realname}-${pkgver} build-${MSYSTEM}

  cd "${srcdir}/build-${MSYSTEM}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}


package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make install DESTDIR="${pkgdir}"

  install -Dm644 COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
